package com.nbot.server.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nbot.server.domain.PlanInjectWaterDO;
import com.nbot.server.service.PlanInjectWaterService;
import com.nbot.server.util.PageUtils;
import com.nbot.server.util.Query;
import com.nbot.server.util.R;
import com.nbot.server.annotation.Log;

/**
 * 最终配注计划
 *
 * @author nbot
 * @email nbot@163.com
 * @date 2018-07-10 15:08:27
 */

@Controller
@RequestMapping("/server/planInjectWater")
public class PlanInjectWaterController {
    @Autowired
    private PlanInjectWaterService planInjectWaterService;

    @GetMapping()
    @RequiresPermissions("server:planInjectWater:planInjectWater")
    String PlanInjectWater() {
        return "server/planInjectWater/planInjectWater" ;
    }

    @ResponseBody
    @Log("查看最终配注计划")
    @GetMapping("/list")
    @RequiresPermissions("server:planInjectWater:planInjectWater")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<PlanInjectWaterDO> planInjectWaterList = planInjectWaterService.list(query);
        int total = planInjectWaterService.count(query);
        PageUtils pageUtils = new PageUtils(planInjectWaterList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("server:planInjectWater:add")
    String add() {
        return "server/planInjectWater/add" ;
    }

    @GetMapping("/edit/{wellName}")
    @RequiresPermissions("server:planInjectWater:edit")
    String edit(@PathVariable("wellName") String wellName, Model model) {
            PlanInjectWaterDO planInjectWater = planInjectWaterService.get(wellName);
        model.addAttribute("planInjectWater" , planInjectWater);
        return "server/planInjectWater/edit" ;
    }

    /**
     * 保存
     */
    @Log("保存最终配注计划")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("server:planInjectWater:add")
    public R save(PlanInjectWaterDO planInjectWater) {
        if (planInjectWaterService.save(planInjectWater) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @Log("修改最终配注计划")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("server:planInjectWater:edit")
    public R update(PlanInjectWaterDO planInjectWater) {
            planInjectWaterService.update(planInjectWater);
        return R.ok();
    }

    /**
     * 删除
     */
    @Log("删除最终配注计划")
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("server:planInjectWater:remove")
    public R remove( String wellName) {
        if (planInjectWaterService.remove(wellName) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @Log("批量删除最终配注计划")
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("server:planInjectWater:batchRemove")
    public R remove(@RequestParam("ids[]") String[]wellNames) {
            planInjectWaterService.batchRemove(wellNames);
        return R.ok();
    }

}
